package com.morningstar.flow.service;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.morningstar.common.result.ServiceCheckResult;
import com.morningstar.flow.dao.entity.FlowProcessGroup;
import com.morningstar.flow.dao.mapper.FlowProcessGroupMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 流程组服务类
 *
 * @author yanglianshan
 */
@Slf4j
@Service
public class FlowProcessGroupService extends ServiceImpl<FlowProcessGroupMapper, FlowProcessGroup> {

    public ServiceCheckResult checkAddAndUpdate(FlowProcessGroup flowProcessGroup) {
        LambdaUpdateWrapper<FlowProcessGroup> checkGroupNameWrapper = new LambdaUpdateWrapper<FlowProcessGroup>()
                .eq(FlowProcessGroup::getProcessGroupName, flowProcessGroup.getProcessGroupName())
                .ne(flowProcessGroup.getProcessGroupId() != null, FlowProcessGroup::getProcessGroupId, flowProcessGroup.getProcessGroupId());
        if (this.count(checkGroupNameWrapper) > 0) {
            return new ServiceCheckResult(true, "流程组名称已存在");
        }
        return new ServiceCheckResult(false);
    }
}
